package com.qingshanhui.home_module.module1;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.qingshanhui.home_module.utils.Banner;

import java.util.List;

/**
 * Desc:顶部Banner控件
 * <p>
 * Author: AnYaBo
 * Date: 2021/1/31
 * Copyright: Copyright (c) 2016-2022
 * Company: @小牛科技
 * Email:anyabo@xiaoniu.com
 * Update Comments:
 */
public class TopBannerWidget extends LinearLayout {
    private Banner mBanner;

    public TopBannerWidget(Context context) {
        this(context,null);
    }

    public TopBannerWidget(Context context, AttributeSet attrs) {
        super(context, attrs);
        initViews(context);
    }

    private void initViews(Context context) {
        mBanner = new Banner(context);
        addView(mBanner);
    }

    public void setData(List<TopBannerModel> topBannerModels){
        mBanner.setData(topBannerModels, new TopBannerViewHolder())
                .setIndicatorRes(android.R.color.holo_green_light,android.R.color.darker_gray)
                .setIndicatorWidthAndHeight(30,5)
                .setLoopDuration(3000)
                .setOnBannerClickListener(new Banner.OnBannerClickListener() {
                    @Override
                    public void onBannerClick(List<Object> data, int position) {
                        TopBannerModel topBannerModel = (TopBannerModel) data.get(position);
                        Toast.makeText(getContext(),topBannerModel.url,Toast.LENGTH_SHORT).show();
                    }
                })
                .start();
    }

}
